<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div>1</div>
    <div>2</div>
    <div>3</div>
    <script>
        let el = console.log;
        let nodes = new WeakSet()
        // 报错 WeakSet(["dushenyan","xiaobudai"])   主要是这里面保存的是引用类型值
        let divs = document.querySelectorAll('div')
        divs.forEach(function (item) {
            nodes.add(item)
        })

        el(nodes)
        //垃圾回收机制
        let hd = {
            name: 'xiaobudai'
        }
        let edu = hd
        hd = null;
        edu = null
        el(edu) //未被引用将会被垃圾回收

        //weakset弱引用类型
        let hd2 = {
            name: 'dushenyan1'
        }
        let referSet = new Set()
        referSet.add(hd2)
        hd2 = null
        // 引用断了后所有Set方法都使用不了
        el(referSet)

        // 让内存读取下值
        setInterval(() => {
            el(referSet)
        }, 2000);
    </script>
</body>

</html>